| 1 | import type { PageServerLoad } from "./$types"; |
| 2 | import type { ImageItem } from "$lib"; |
| 3 | import { error } from "@sveltejs/kit"; |
| 4 | |
| 5 | const R2_BASE_URL = "https://r2.steve.photo"; |
| 6 | |
| 7 | export const load: PageServerLoad = async ({ platform, params }) => { |
| 8 | const db = platform?.env?.DB; |
| 9 | |
| 10 | const result = await db |
| 11 | .prepare("SELECT * FROM photos WHERE slug = ?") |
| 12 | .bind(params.slug) |
| 13 | .first(); |
| 14 | |
| 15 | if (!result) { |
| 16 | throw error(404, "Photo not found"); |
| 17 | } |
| 18 | |
| 19 | const photo: ImageItem = { |
| 20 | slug: result.slug as string, |
| 21 | title: result.title as string, |
| 22 | date: result.date as string, |
| 23 | image: `${R2_BASE_URL}/${result.image_key}`, |
| 24 | thumb: `${R2_BASE_URL}/${result.thumb_key}`, |
| 25 | type: result.type as string, |
| 26 | camera: result.camera as string, |
| 27 | lens: result.lens as string, |
| 28 | aperture: result.aperture as string, |
| 29 | exposure: result.exposure as string, |
| 30 | focalLength: result.focal_length as string, |
| 31 | iso: result.iso as string, |
| 32 | make: result.make as string, |
| 33 | tags: [], |
| 34 | blurData: result.blur_data as string, |
| 35 | }; |
| 36 | |
| 37 | return { photo }; |
| 38 | }; |